﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class Checkpoint : MonoBehaviour
{
    Button checkpointButton0;
    Button checkpointButton1;
    Button checkpointButton2;
    Button checkpointButton3;
    Button checkpointButton4;
    Button checkpointButton5;
    Button checkpointButton6;
    GameObject data;
    // Start is called before the first frame update
    void Start()
    {
        data = GameObject.FindGameObjectWithTag("Data");
        checkpointButton0 = transform.GetChild(0).GetChild(0).GetComponent<Button>();
        checkpointButton1 = transform.GetChild(1).GetChild(0).GetComponent<Button>();
        checkpointButton2 = transform.GetChild(2).GetChild(0).GetComponent<Button>();
        checkpointButton3 = transform.GetChild(3).GetChild(0).GetComponent<Button>();
        checkpointButton4 = transform.GetChild(4).GetChild(0).GetComponent<Button>();
        checkpointButton5 = transform.GetChild(5).GetChild(0).GetComponent<Button>();
        checkpointButton6 = transform.GetChild(6).GetChild(0).GetComponent<Button>();
        checkpointButton0.onClick.AddListener(
            delegate
            {
                ThresholdAssignment(0);
            });
        checkpointButton1.onClick.AddListener(
            delegate
            {
                ThresholdAssignment(1);
            });
        checkpointButton2.onClick.AddListener(
            delegate
            {
                ThresholdAssignment(2);
            });
        checkpointButton3.onClick.AddListener(
            delegate
            {
                ThresholdAssignment(3);
            });
        checkpointButton4.onClick.AddListener(
            delegate
            {
                ThresholdAssignment(4);
            });
        checkpointButton5.onClick.AddListener(
            delegate
            {
                ThresholdAssignment(5);
            });
        checkpointButton6.onClick.AddListener(
            delegate
            {
                ThresholdAssignment(6);
            });
    }

    void ThresholdAssignment(int i)
    {
        if (data .GetComponent <GameData >().combatMaxValue>=i)
        {
            data.GetComponent<GameData>().combatLevel = i;
            SceneManager.LoadScene("PlayGame");

        }
    }


    // Update is called once per frame
    void Update()
    {
        
    }
}
